package com.binhthuan.catechist.server;

import java.util.Collection;

import com.binhthuan.catechist.server.domain.AbstractObject;
import com.google.gson.annotations.Expose;

public class QueryObject {
    @Expose
    private Integer status;
    @Expose
    private Integer startRow;
    @Expose
    private Integer endRow;
    @Expose
    private Integer totalRows;
    @Expose
    private Object data;

    public QueryObject() {
        this(0, 0, 0, 0, null);
    }

    @SuppressWarnings("unchecked")
    public QueryObject(Object data) {
        this(0, 0, 0, 0, data);
        if (data == null) {

        } else if (data instanceof Collection<?>) {
            totalRows = ((Collection<AbstractObject>) data).size();
            endRow = totalRows > 0 ? totalRows - 1 : 0;
        } else {
            endRow = 0;
            totalRows = 1;
        }
    }

    public QueryObject(Integer status, Integer startRow, Integer endRow, Integer totalRows, Object data) {
        super();
        this.status = status;
        this.startRow = startRow;
        this.endRow = endRow;
        this.totalRows = totalRows;
        this.data = data;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer getStartRows() {
        return startRow;
    }

    public void setStartRows(Integer startRow) {
        this.startRow = startRow;
    }

    public Integer getEndRow() {
        return endRow;
    }

    public void setEndRow(Integer endRow) {
        this.endRow = endRow;
    }

    public Integer getTotalRows() {
        return totalRows;
    }

    public void setTotalRows(Integer totalRows) {
        this.totalRows = totalRows;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
